home *** CD-ROM | disk | FTP | other *** search
/ Acorn RISC PD-CD 1 / Acorn RISC PD-CD 1.iso / languages / dde / _pc / h / txtedit < prev    next >
Encoding:
Text File  |  1992-02-10  |  13.9 KB  |  348 lines

  1. (* 
  2.  * Title: txtedit.h
  3.  * Purpose: Text editing facilities.
  4.  *
  5.  *)
  6.  
  7. # ifndef __txtedit_h
  8. # define __txtedit_h
  9.  
  10. # ifndef __txt_h
  11. # include "txt.h"
  12. # endif
  13.  
  14. # ifndef __typdat_h
  15. # include "typdat.h"
  16. # endif
  17.  
  18. #ifndef __menu_h
  19. #include "menu.h"
  20. #endif
  21.  
  22. (****************************** DATA TYPES *********************************)
  23.  
  24. const
  25.     txtedit_CHARSEL = 1;
  26.     txtedit_WORDSEL = 2;
  27.     txtedit_LINESEL = 4;
  28.  
  29. type txtedit_seltype = integer;
  30.  
  31. type txtedit_state_ptr = ^txtedit_state;
  32.      txtedit_state =
  33.        record
  34.          t : txt;
  35.          selpivot : txt_marker;       (* used in mouse op calculations *)
  36.          seltype : txtedit_seltype;   (* used in mouse op calculations *)
  37.          selectrecent : integer;      (* used in mouse op calculations *)
  38.          selectctl : integer;         (* used in mouse op calculations *)
  39.          filename : packed array[1..255] of char;
  40.          ty : typdat;
  41.          deletepending : integer;
  42.          next : txtedit_state_ptr;    (* chain of all of them. *)
  43.          overwrite : integer;
  44.          wordtab : integer;
  45.          wordwrap : integer
  46.        end;
  47.  
  48. type txtedit_update_handler = ^function update_handler(s : string;
  49.                                          state : txtedit_state_ptr;
  50.                                          handle : pointer) : boolean;
  51. type txtedit_close_handler = ^procedure close_handler(s : string;
  52.                                          state : txtedit_state_ptr;
  53.                                          handle : pointer);
  54. type txtedit_save_handler = ^function save_handler(s : string;
  55.                                          state : txtedit_state_ptr;
  56.                                          handle : pointer) : boolean;
  57. type txtedit_shutdown_handler = ^procedure shutdown_handler(
  58.                                          handle : pointer);
  59. type txtedit_undofail_handler = ^procedure undofail_handler(s : string;
  60.                                          state : txtedit_state_ptr;
  61.                                          handle : pointer);
  62. type txtedit_open_handler = ^procedure open_handler(s : string;
  63.                                          state : txtedit_state_ptr;
  64.                                          handle : pointer);
  65.  
  66. (**************************** INTERFACE FUNCTIONS *************************)
  67.  
  68.  
  69. (* --------------------------- txtedit_install -----------------------------
  70.  * Description:   Installs an event handler for the txt t, thus making it
  71.  *                an editable text.
  72.  *
  73.  * Parameters:    txt t -- the text object (created via txt_new)
  74.  * Returns:       A pointer to the resulting txtedit_state.
  75.  * Other Info:    none.
  76.  *
  77.  *)
  78. function txtedit_install(t : txt) : txtedit_state_ptr; extern;
  79.  
  80.  
  81. (* ----------------------------- txtedit_new -------------------------------
  82.  * Description:   Creates a new text object, loads the given file into it
  83.  *                and the text can now be edited.
  84.  *
  85.  * Parameters:    char *filename -- the file to be loaded.
  86.  * Returns:       a pointer to the txtedit_state for this text.
  87.  * Other Info:    If the file cannot be found, then 0 is returned as a 
  88.  *                result, and no text is created. If "filename" is a null
  89.  *                pointer, then an editor window with no given file name
  90.  *                will be constructed. If the file is already being edited,
  91.  *                then a pointer to the existing txtedit_state is returned.
  92.  *
  93.  *)
  94. function txtedit_new(filename : string) : txtedit_state_ptr; extern;
  95.  
  96.  
  97. (* ---------------------------- txtedit_dispose ----------------------------
  98.  * Description:   Destroys the given text being edited.
  99.  *
  100.  * Parameters:    txtedit_state *s -- the text to be destroyed.
  101.  * Returns:       void.
  102.  * Other Info:    Note: this will ask no questions of the user before
  103.  *                destroying the text.
  104.  *
  105.  *)
  106. procedure txtedit_dispose(s : txtedit_state_ptr); extern;
  107.  
  108.  
  109. (* --------------------------- txtedit_mayquit -----------------------------
  110.  * Description:   Check if we may safely quit editing.
  111.  *
  112.  * Parameters:    void.
  113.  * Returns:       TRUE if we may safely quit, otherwise FALSE.
  114.  * Other Info:    If a text is being edited, then a dialogue box is displayed
  115.  *                asking the user if he really wants to quit.
  116.  *                This calls dboxquery(), and therefore requires the 
  117.  *                template "query" as described in dboxquery.h.
  118.  *
  119.  *)
  120. function txtedit_mayquit : boolean; extern;
  121.  
  122.  
  123. (* ----------------------------- txtedit_prequit ---------------------------
  124.  * Description:   Deal with a PREQUIT message from the task manager.
  125.  *
  126.  * Parameters:    void.
  127.  * Returns:       void.
  128.  * Other Info:    Calls txtedit_mayquit(), to see if we may quit, if text
  129.  *                is being edited. If user replies that we may quit, then
  130.  *                all texts are disposed of, and this function sends an
  131.  *                acknowledgement to the task manager.
  132.  *
  133.  *)
  134. procedure txtedit_prequit; extern;
  135.  
  136.  
  137. (* ---------------------------- txtedit_menu -------------------------------
  138.  * Description:   Sets up a menu structure for the text being edited,
  139.  *                tailored to its current state.
  140.  *
  141.  * Parameters:    txtedit_state * s -- the text's current state.
  142.  * Returns:       a pointer to an appropriately formed menu structure
  143.  * Other Info:    The menu created will have the same form as that displayed
  144.  *                when mouse menu button is clicked on an !Edit window.
  145.  *                (For !Edit version 1.00).
  146.  *                Entries in the menu are set according to the supplied
  147.  *                txtedit_state.
  148.  *)
  149. function txtedit_menu(s : txtedit_state_ptr) : menu; extern;
  150.  
  151.  
  152. (*------------------------------ txtedit_menuevent -------------------------
  153.  * Description:   Apply a given menu hit to a given text.
  154.  *
  155.  * Parameters:    txtedit_state *s -- the text to which hit should be applied
  156.  *                char *hit -- a menu hit string.
  157.  * Returns:       void.
  158.  * Other Info:    This can be called from a menu event handler.
  159.  *
  160.  *)
  161. procedure txtedit_menuevent(s : txtedit_state_ptr; hit : string); extern;
  162.  
  163.  
  164. (* --------------------------- txtedit_doimport ----------------------------
  165.  * Description:   Import data into the specified txtedit object, from a file
  166.  *                of a given type.
  167.  *
  168.  * Parameters:    txtedit_state *s -- the text object
  169.  *                int filetype -- type of the file
  170.  *                int estsize -- file's estimated size.
  171.  * Returns:       TRUE if import completed successfully.
  172.  * Other Info:    none.
  173.  *
  174.  *)
  175. function txtedit_doimport(s : txtedit_state_ptr;
  176.                 filetype : integer;
  177.                 estsize : integer) : boolean; extern;
  178.  
  179.  
  180. (* ------------------------- txtedit_doinsertfile --------------------------
  181.  * Description:   Inserts a named file in a given text object.
  182.  *
  183.  * Parameters:    txtedit_state *s -- the text object
  184.  *                char *filename -- the given file
  185.  *                BOOL replaceifwasnull -- if set to TRUE then the text
  186.  *                                         object will be considred to have
  187.  *                                         come from "filename", ie. window
  188.  *                                         title is updated.
  189.  *
  190.  * Returns:       void.
  191.  * Other Info:    none.
  192.  *
  193.  *)
  194. procedure txtedit_doinsertfile(s : txtedit_state_ptr;
  195.                 filename : string;
  196.                 replaceifwasnull : boolean); extern;
  197.  
  198.  
  199. (* ------------------------ txtedit_register_update_handler ---------------
  200.  * Description:   Register a handler to be called when a text window is 
  201.  *                modified
  202.  *
  203.  * Parameters:    txtedit_handler h -- the handler function
  204.  *                void *handle      -- handle to be passed to the function
  205.  * Returns:       previous handler
  206.  * Other Info:    This routine will be called whenever a window's title bar
  207.  *                is redrawn, and the text in the window has been modified.
  208.  *                Note: this is not just called when the '*' first appears 
  209.  *                in a window's title bar, but every time the title bar of a
  210.  *                modified text window is redrawn (eg. when the filename
  211.  *                changes or wordwrap is turned on/off etc).
  212.  *                The handler function will be passed:
  213.  *                       i) the filename for the window title
  214.  *                      ii) the address of this 'txtedit_state'
  215.  *                     iii) the handle registered with this function
  216.  *                If the handler returns FALSE, then the last modification
  217.  *                will be undone.  This is only possible if the modification
  218.  *                is not greater than ~5kb.
  219.  *                Calling with h == 0 removes the handler.
  220.  *
  221.  *)
  222. procedure txtedit_register_update_handler(h : txtedit_update_handler;
  223.                 handle : pointer) : txtedit_update_handler; extern;
  224.  
  225.  
  226. (* ------------------------ txtedit_register_save_handler ------------------
  227.  * Description:   Register a handler to be called when a text window is 
  228.  *                saved
  229.  *
  230.  * Parameters:    txtedit_handler h -- the handler function
  231.  *                void *handle      -- handle to be passed to the function
  232.  * Returns:       previous handler
  233.  * Other Info:    This routine will be called whenever a text window is saved
  234.  *                to file (NOT via RAM transfer).
  235.  *                The handler function will be passed:
  236.  *                       i) the filename for the window title
  237.  *                      ii) the address of this 'txtedit_state'
  238.  *                     iii) the handle registered with this function
  239.  *                Calling with h == 0 removes the handler.
  240.  *                Returning FALSE from your handler will abort the save
  241.  *                operation.
  242.  *
  243.  *)
  244. procedure txtedit_register_save_handler(h : txtedit_save_handler;
  245.                 handle : pointer) : txtedit_save_handler; extern;
  246.  
  247.  
  248. (* ------------------------ txtedit_register_close_handler ----------------
  249.  * Description:   Register a handler to be called when a modified text 
  250.  *                window is closed
  251.  *
  252.  * Parameters:    txtedit_handler h -- the handler function
  253.  *                void *handle      -- handle to be passed to the function
  254.  * Returns:       previous handler
  255.  * Other Info:    This routine will be called whenever a text
  256.  *                window is closed.
  257.  *                The handler function will be passed:
  258.  *                       i) the filename for the window title
  259.  *                      ii) the address of this 'txtedit_state'
  260.  *                     iii) the handle registered with this function
  261.  *                Calling with h == 0 removes the handler.
  262.  *
  263.  *)
  264. procedure txtedit_register_close_handler(h : txtedit_close_handler;
  265.                 handle : pointer) : txtedit_close_handler; extern;
  266.  
  267. (* ------------------------ txtedit_register_shutdown_handler --------------
  268.  * Description:   Register a handler to be called when txtedit_prequit() is
  269.  *                called. 
  270.  *
  271.  * Parameters:    txtedit_handler h -- the handler function
  272.  *                void *handle      -- handle to be passed to the function
  273.  * Returns:       previous handler
  274.  * Other Info:    This routine will be called whenever txtedit_prequit() is
  275.  *                called, and the user answers "yes" when asked if he really
  276.  *                wants to quit edit, or no files have been modified.
  277.  *                The handler function will be passed the handle
  278.  *                registered with this function
  279.  *                Calling with h == 0 removes the handler.
  280.  *
  281.  *)
  282. procedure txtedit_register_shutdown_handler(h : txtedit_shutdown_handler;
  283.                 handle : pointer) : txtedit_shutdown_handler; extern;
  284.  
  285. (* ------------------------ txtedit_register_undofail_handler --------------
  286.  * Description:   Register a handler to be called when your update_handler
  287.  *                returned FALSE, and the undo buffer overflowed. 
  288.  *
  289.  * Parameters:    txtedit_handler h -- the handler function
  290.  *                void *handle      -- handle to be passed to the function
  291.  * Returns:       previous handler
  292.  * Other Info:    This will be called when the modification made to an
  293.  *                edited file cannot be undone (only in conjunction with
  294.  *                an update handler).
  295.  *                The handler function will be passed:
  296.  *                       i) the filename for the window title
  297.  *                      ii) the address of this 'txtedit_state'
  298.  *                     iii) the handle registered with this function
  299.  *                Calling with h == 0 removes the handler.
  300.  *
  301.  *)
  302. procedure txtedit_register_undofail_handler(h : txtedit_undofail_handler;
  303.                 handle : pointer) : txtedit_undofail_handler; extern;
  304.  
  305. (* ----------------------- txtedit_register_open_handler -------------------
  306.  * Description:   Register a handler to be called when a new txtedit_state is
  307.  *                created. 
  308.  *
  309.  * Parameters:    txtedit_handler h -- the handler function
  310.  *                void *handle      -- handle to be passed to the function
  311.  * Returns:       previous handler
  312.  * Other Info:    The handler function will be passed:
  313.  *                       i) the filename for the window title
  314.  *                      ii) the address of this 'txtedit_state'
  315.  *                     iii) the handle registered with this function
  316.  *                Calling with h == 0 removes the handler.
  317.  *
  318.  *)
  319. procedure txtedit_register_open_handler(h : txtedit_open_handler;
  320.                 handle : pointer) : txtedit_open_handler; extern;
  321.  
  322. (* ---------------------------- txtedit_getstates --------------------------
  323.  * Description:   Get a pointer to the list of current txtedit_states
  324.  *
  325.  * Parameters:    void.
  326.  * Returns:       Pointer to the list of txtedit_states
  327.  * Other Info:    The txtedit part of RISC_OSlib keeps a list of all
  328.  *                txtedit_states created (via txtedit_new). This function
  329.  *                allows access to this list
  330.  *
  331.  *)
  332. function txtedit_getstates : txtedit_state_ptr; extern;
  333.  
  334.  
  335. (* ---------------------------- txtedit_init -------------------------------
  336.  * Description:   Initialise the txtedit module of the library
  337.  *
  338.  * Parameters:    void.
  339.  * Returns:       void.
  340.  * Other Info:    none.
  341.  *
  342.  *)
  343. procedure txtedit_init; extern;
  344.  
  345. #endif
  346.  
  347. (* end txtedit.h *)
  348.